import { Service } from 'egg';

export class PagesService extends Service {
    public async create() {
        const { app, ctx } = this;
        const { model } = app;
        try {
            await model.transaction(async transaction => {
                for (let i = 0; i < 378; i++) {
                    await model.Pages.create({
                        url: `http://bizsearch.winshangdata.com/xiangmu/s0-c0-t0-k0-x0-d0-z0-n0-m0-l0-q0-b0-y0-pn${i + 1}.html`,
                        status: 'waiting',
                    }, {
                        transaction,
                    });
                }
            });
        } catch (err) {
            ctx.throw(500, err.message);
        }

        return {
            status: 0,
            msg: 'success',
        }
    }
}

export default PagesService;
